package proto

import (
	"common"
	"framework/msError"
	"hall/models/response"
)

type RoomUser struct {
	UserInfo   response.GameRoleInfo `json:"userInfo"`
	ChairID    int                   `json:"chairID"`
	UserStatus UserStatus            `json:"userStatus"`
}

type UserStatus int

const (
	None    UserStatus = 0 //未准备
	Ready              = 1 //准备
	Playing            = 2 //开始游戏
	Offline            = 4 //掉线
	Dismiss            = 8 //退出
)

func ToRoomUser(data response.GameRoleInfo, chairID int) *RoomUser {
	return &RoomUser{
		UserInfo:   data,
		ChairID:    chairID,
		UserStatus: None,
	}
}

type RoomMessageType int

const (
	UserReadyNotify             RoomMessageType = 301 // 用户准备的通知
	UserReadyPush               RoomMessageType = 401 // 用户准备的推送
	OtherUserEntryRoomPush      RoomMessageType = 402 // 用户进入房间的推送
	UserLeaveRoomNotify         RoomMessageType = 303 // 用户离开房间的通知
	UserLeaveRoomResponse       RoomMessageType = 403 //用户离开房间的回复
	UserLeaveRoomPush           RoomMessageType = 404 //用户离开房间的推送
	GetRoomSceneInfoPush        RoomMessageType = 418 // 获取房间场景信息的推送
	DismissPush                 RoomMessageType = 405 //房间解散的推送
	UserInfoChangePush          RoomMessageType = 406 //房间用户信息变化的推送
	UserChatNotify              RoomMessageType = 307 // 用户聊天通知
	UserChatPush                RoomMessageType = 407 // 用户聊天推送
	UserOffLinePush             RoomMessageType = 408 //用户掉线的推送
	DrawFinishedPush            RoomMessageType = 409 //开设的房间局数用完推送
	UserReconnectNotify         RoomMessageType = 312 //玩家断线重连
	UserReconnectPush           RoomMessageType = 412 //
	AskForDismissNotify         RoomMessageType = 313 //玩家请求解散房间
	AskForDismissPush           RoomMessageType = 413 //
	EndPush                     RoomMessageType = 414 //最终结果推送
	AskForDismissStatusNotify   RoomMessageType = 316
	AskForDismissStatusPush     RoomMessageType = 416
	GetRoomShowUserInfoNotify   RoomMessageType = 317 // 获取房间需要显示的玩家信息通知
	GetRoomShowUserInfoPush     RoomMessageType = 417 // 获取房间需要显示的玩家信息推送
	GetRoomSceneInfoNotify      RoomMessageType = 318 // 获取房间场景信息的通知
	GetRoomOnlineUserInfoNotify RoomMessageType = 319 // 获取房间在线用户信息的通知
	GetRoomOnlineUserInfoPush   RoomMessageType = 419
	UserChangeSeatNotify        RoomMessageType = 320 //换座通知
	UserChangeSeatPush          RoomMessageType = 420
	RoomErrorNotify             RoomMessageType = 444
)

func UpdateUserInfoPush(roomId string, chairID int) any {
	pushMsg := map[string]any{
		"data": map[string]any{
			"roomId":  roomId,
			"chairID": chairID,
		},
		"pushRouter": "UpdateUserInfoPush",
	}
	return pushMsg
}
func SelfEntryRoomPush(gameID uint) any {
	pushMsg := map[string]any{
		"gameType":   gameID,
		"pushRouter": "SelfEntryRoomPush",
	}
	return pushMsg
}

func UserLeaveRoomResponseData(err *msError.Error) any {
	var data common.Result
	if err == nil {
		data = common.S(err)
	} else {
		data = common.F(err)
	}
	pushMsg := map[string]any{
		"type":       UserLeaveRoomResponse,
		"data":       data,
		"pushRouter": "RoomMessagePush",
	}
	return pushMsg
}

func UserReadyPushData(chairID int, ready bool) any {
	pushMsg := map[string]any{
		"type": UserReadyPush,
		"data": map[string]any{
			"ready":   ready,
			"chairID": chairID,
		},
		"pushRouter": "RoomMessagePush",
	}
	return pushMsg
}

func UserLeaveRoomPushData(chairID int) any {
	pushMsg := map[string]any{
		"type": UserLeaveRoomPush,
		"data": map[string]any{
			"chairID": chairID,
		},
		"pushRouter": "RoomMessagePush",
	}
	return pushMsg
}

func OtherUserEntryRoomPushData(roomUserInfo *RoomUser) any {
	pushMsg := map[string]any{
		"type": OtherUserEntryRoomPush,
		"data": map[string]any{
			"roomUserInfo": roomUserInfo,
		},
		"pushRouter": "RoomMessagePush",
	}
	return pushMsg
}

func UserEntryRoomPushData(roomUserData []*RoomUser) any {
	pushMsg := map[string]any{
		"type": OtherUserEntryRoomPush,
		"data": map[string]any{
			"roomUserData": roomUserData,
		},
		"pushRouter": "RoomMessagePush",
	}
	return pushMsg
}

func GetRoomSceneInfoPushData(gameRule any) any {
	pushMsg := map[string]any{
		"type": GetRoomSceneInfoPush,
		"data": map[string]any{
			"gameRule": gameRule,
		},
		"pushRouter": "RoomMessagePush",
	}
	return pushMsg
}

func RoomErrorNotifyData(result common.Result) any {
	return map[string]any{
		"type":       RoomErrorNotify,
		"data":       result,
		"pushRouter": "RoomMessagePush",
	}
}
